#include <stdio.h>
#include <stdlib.h>
#include <string.h>

void str_to_hex(unsigned char *dest_hex, char *src_str, int str_length)
{
    int i,j=0;
    unsigned char  char_to_uint8 = 0;
    for(i=0,j=0;i<str_length;i=i+2,j++)
    {
        switch(*(src_str+i))
        {
        case '0':
            char_to_uint8 = (unsigned char)0x00<<4;
            break;
        case '1':
            char_to_uint8 = (unsigned char)0x01<<4;
            break;
        case '2':
            char_to_uint8 = (unsigned char)0x02<<4;
            break;
        case '3':
            char_to_uint8 = (unsigned char)0x03<<4;
            break;
        case '4':
            char_to_uint8 = (unsigned char)0x04<<4;
            break;
        case '5':
            char_to_uint8 = (unsigned char)0x05<<4;
            break;
        case '6':
            char_to_uint8 = (unsigned char)0x06<<4;
            break;
        case '7':
            char_to_uint8 = (unsigned char)0x07<<4;
            break;
        case '8':
            char_to_uint8 = (unsigned char)0x08<<4;
            break;
        case '9':
            char_to_uint8 = (unsigned char)0x09<<4;
            break;
        case 'A':
            char_to_uint8 = (unsigned char)0x0a<<4;
            break;
        case 'B':
            char_to_uint8 = (unsigned char)0x0b<<4;
            break;
        case 'C':
            char_to_uint8 = (unsigned char)0x0c<<4;
            break;
        case 'D':
            char_to_uint8 = (unsigned char)0x0d<<4;
            break;
        case 'E':
            char_to_uint8 = (unsigned char)0x0e<<4;
            break;
        case 'F':
            char_to_uint8 = (unsigned char)0x0f<<4;
            break;
        default :
            break;
        }
        switch(*(src_str+i+1))
        {
        case '0':
            char_to_uint8 |= (unsigned char)0x00;
            break;
        case '1':
            char_to_uint8 |= (unsigned char)0x01;
            break;
        case '2':
            char_to_uint8 |= (unsigned char)0x02;
            break;
        case '3':
            char_to_uint8 |= (unsigned char)0x03;
            break;
        case '4':
            char_to_uint8 |= (unsigned char)0x04;
            break;
        case '5':
            char_to_uint8 |= (unsigned char)0x05;
            break;
        case '6':
            char_to_uint8 |= (unsigned char)0x06;
            break;
        case '7':
            char_to_uint8 |= (unsigned char)0x07;
            break;
        case '8':
            char_to_uint8 |= (unsigned char)0x08;
            break;
        case '9':
            char_to_uint8 |= (unsigned char)0x09;
            break;
        case 'A':
            char_to_uint8 |= (unsigned char)0x0a;
            break;
        case 'B':
            char_to_uint8 |= (unsigned char)0x0b;
            break;
        case 'C':
            char_to_uint8 |= (unsigned char)0x0c;
            break;
        case 'D':
            char_to_uint8 |= (unsigned char)0x0d;
            break;
        case 'E':
            char_to_uint8 |= (unsigned char)0x0e;
            break;
        case 'F':
            char_to_uint8 |= (unsigned char)0x0f;
            break;
        default :
            break;
        }
        *(dest_hex+j) = char_to_uint8;
        char_to_uint8 = 0;
    }
}

unsigned char rtcm_src[1024] = {"D300133ED342027A95E7B9E08C8BDCB31805CB779783A82BFBD300153EE342033A95E7B9E08C8BDCB31805CB7797830000B60469D30009409342000000000000B3B479D3005943234243B7A1E20000260D100400000000200000007FA3A2A627A3A728273309F5603A074221F28B8DAE0F364BC76867D73219652BC8CE8372FE0884E8476C5EA9D47FC16E10F66047ACA12392FFFFFFFF805D8C755F5CF5008615B2D3007246434243B6C72000007EEC000000000000200000007FF7B7C79808279797D844A7BA605874464ADD1AF664A61050E276B8F6DF3C2DC63C291175DEEE1A5B05E41B6E2D93ECD25FDB78A1E0C5FC71E60307A05E821F676A7A4ECE0B7F886F3FE15CE5FFFFFFFFFFF800AA8B288ECAE98EEB40771B4F"};
unsigned char rtcm_hex_[1024] = {0};

void char_to_hex(char * dest, unsigned char * src)
{
    int i;
    unsigned char hex = 0;
    int index = 0;
    
    for(i=0;i<strlen((char *)src);i=i+2)
    {
        if((src[i]>='0')&&(src[i]<='9'))
        {
            hex = (src[i]-'0')<<4;
        }
        else if((src[i]>='A')&&(src[i]<='F'))
        {
            hex = (src[i]-'A'+10)<<4;
        }
        
        if((src[i+1]>='0')&&(src[i+1]<='9'))
        {
            hex |= (src[i+1]-'0');
        }
        else if((src[i+1]>='A')&&(src[i+1]<='F'))
        {
            hex |= (src[i+1]-'A'+10);
        }
        dest[index++] = hex;
    }
 }

char * hex_to_char(char * dst, unsigned char * src, int len)
{
    int i = 0;

    for(i = 0; i < len; i++)
    {
        sprintf((char *)dst,"%02X",src[i]);
        dst+=2;
    }

    return dst;
}
